home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / raytrace / real3d / rl_dvlpr.lha / Source / hr_r3d.library.asm < prev    next >
Assembly Source File  |  1992-07-22  |  10KB  |  410 lines

  1.  
  2. ;-----------------------------------------------------------------------
  3. ; This file contains library handling routines and entry functions, 
  4. ; which push arguments into stack and call the actual C language routines 
  5. ; contained in the file hrcode.c. If you want to use this example when 
  6. ; creating a new interface library, change the library name strings to 
  7. ; match the new library name and reassemble the file:
  8. ;
  9. ;   'asm  hr_r3d.library.asm'
  10.  
  11.  
  12.    SECTION   code
  13.  
  14.    NOLIST
  15.    INCLUDE "exec/types.i"
  16.    INCLUDE "exec/initializers.i"
  17.    INCLUDE "exec/libraries.i"
  18.    INCLUDE "exec/lists.i"
  19.    INCLUDE "exec/alerts.i"
  20.    INCLUDE "exec/resident.i"
  21.    INCLUDE "libraries/dos.i"
  22.  
  23.    INCLUDE "asmsupp.i"
  24.    INCLUDE "dspdrvbase.i"
  25.  
  26.    LIST
  27.  
  28.    ;------ These don't have to be external, but it helps some
  29.    ;------ debuggers to have them globally visible
  30.    XDEF   Init
  31.    XDEF   Open
  32.    XDEF   Close
  33.    XDEF   Expunge
  34.    XDEF   Null
  35.    XDEF   libraryName
  36.  
  37.    XREF   _R3DInitDspDrv
  38.    XREF   _R3DFreeDspDrv
  39.    XREF   _R3DSetMode
  40.    XREF   _R3DGetSize
  41.    XREF   _R3DWriteLine
  42.    XREF   _R3DReadLine
  43.    XREF   _R3DClsScr
  44.    XREF   _R3DCustomSave
  45.         
  46.    XREF   _AbsExecBase
  47.    XREF   _R3DDspDrvBase
  48.  
  49.    XLIB   OpenLibrary
  50.    XLIB   CloseLibrary
  51.    XLIB   Alert
  52.    XLIB   FreeMem
  53.    XLIB   Remove
  54.  
  55.  
  56.  
  57.    ; The first executable location.  This should return an error
  58.    ; in case someone tried to run you as a program (instead of
  59.    ; loading you as a library).
  60. Start:
  61.    MOVEQ   #-1,d0
  62.    rts
  63.  
  64. ;-----------------------------------------------------------------------
  65. ; A romtag structure.  Both "exec" and "ramlib" look for
  66. ; this structure to discover magic constants about you
  67. ; (such as where to start running you from...).
  68. ;-----------------------------------------------------------------------
  69.  
  70.    ; Most people will not need a priority and should leave it at zero.
  71.    ; the RT_PRI field is used for configuring the roms.  Use "mods" from
  72.    ; wack to look at the other romtags in the system
  73. MYPRI   EQU   0
  74.  
  75. initDDescrip:
  76.                ;STRUCTURE RT,0
  77.      DC.W    RTC_MATCHWORD      ; UWORD RT_MATCHWORD
  78.      DC.L    initDDescrip       ; APTR  RT_MATCHTAG
  79.      DC.L    EndCode            ; APTR  RT_ENDSKIP
  80.      DC.B    RTF_AUTOINIT       ; UBYTE RT_FLAGS
  81.      DC.B    VERSION            ; UBYTE RT_VERSION
  82.      DC.B    NT_LIBRARY         ; UBYTE RT_TYPE
  83.      DC.B    MYPRI              ; BYTE  RT_PRI
  84.      DC.L    libraryName        ; APTR  RT_NAME
  85.      DC.L    idString           ; APTR  RT_IDSTRING
  86.      DC.L    Init               ; APTR  RT_INIT
  87.  
  88.  
  89.    ; this is the name that the library will have
  90. libraryName:   dc.b   'hr_r3d.library',0
  91.  
  92.    ; a major version number.
  93. VERSION:   EQU   34
  94.  
  95.    ; A particular revision.  This should uniquely identify the bits in the
  96.    ; library.  I use a script that advances the revision number each time
  97.    ; I recompile.  That way there is never a question of which library
  98.    ; that really is.
  99. REVISION:   EQU  1
  100.  
  101.    ; this is an identifier tag to help in supporting the library
  102.    ; format is 'name version.revision (dd MON yyyy)',<cr>,<lf>,<null>
  103. idString:   dc.b   'hr_r3d.library 1.0 (10 Jan 1992)',13,10,0
  104.  
  105. dosName:   DOSNAME
  106.  
  107.    ; force word alignment
  108.    ds.w   0
  109.  
  110.  
  111.    ; The romtag specified that we were "RTF_AUTOINIT".  This means
  112.    ; that the RT_INIT structure member points to one of these
  113.    ; tables below.  If the AUTOINIT bit was not set then RT_INIT
  114.    ; would point to a routine to run.
  115.  
  116. Init:
  117.    DC.L   R3DDspDrvBase_SIZEOF ; size of library base data space
  118.    DC.L   funcTable            ; pointer to function initializers
  119.    DC.L   dataTable            ; pointer to data initializers
  120.    DC.L   initRoutine          ; routine to run
  121.  
  122.  
  123. funcTable:
  124.  
  125.    ;------ standard system routines
  126.    dc.l   Open
  127.    dc.l   Close
  128.    dc.l   Expunge
  129.    dc.l   Null
  130.  
  131.    ;------ my library functions
  132.    dc.l   R3DInitDspDrv
  133.    dc.l   R3DFreeDspDrv
  134.    dc.l   R3DSetMode
  135.    dc.l   R3DGetSize
  136.    dc.l   R3DWriteLine
  137.    dc.l   R3DReadLine
  138.    dc.l   R3DClsScr
  139.    dc.l   R3DCustomSave
  140.  
  141.    ;------ function table end marker
  142.    dc.l   -1
  143.  
  144.  
  145.    ; The data table initializes static data structures.
  146.    ; The format is specified in exec/InitStruct routine's
  147.    ; manual pages.  The INITBYTE/INITWORD/INITLONG routines
  148.    ; are in the file "exec/initializers.i".  The first argument
  149.    ; is the offset from the library base for this byte/word/long.
  150.    ; The second argument is the value to put in that cell.
  151.    ; The table is null terminated
  152.  
  153. dataTable:
  154.     INITBYTE    LN_TYPE,NT_LIBRARY
  155.     INITLONG    LN_NAME,libraryName
  156.     INITBYTE    LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  157.     INITWORD    LIB_VERSION,VERSION
  158.     INITWORD    LIB_REVISION,REVISION
  159.     INITLONG    LIB_IDSTRING,idString
  160.     DC.L   0
  161.  
  162.  
  163.    ; This routine gets called after the library has been allocated.
  164.    ; The library pointer is in D0.  The segment list is in A0.
  165.    ; If it returns non-zero then the library will be linked into
  166.    ; the library list.
  167. initRoutine:
  168.  
  169.    ;------ get the library pointer into a convenient A register
  170.    move.l   a5,-(sp)
  171.    move.l   d0,a5
  172.    move.l   d0,_R3DDspDrvBase
  173.  
  174.    ;------ save a pointer to exec
  175.    move.l   a6,sb_SysLib(a5)
  176.  
  177.    ;------ save a pointer to our loaded code
  178.    move.l   a0,sb_SegList(a5)
  179.  
  180.    ;------ open the dos library
  181.    lea   dosName(pc),a1
  182.    CLEAR   d0
  183.    CALLSYS   OpenLibrary
  184.  
  185.    move.l   d0,sb_DosLib(a5)
  186.    bne.s   1$
  187.  
  188.    ;------ can't open the dos!  what gives
  189.    ALERT   AG_OpenLib!AO_DOSLib
  190.  
  191. 1$:
  192.    ;------ now build the static data that we need
  193.    ;
  194.    ; put your initialization here...
  195.    ;
  196.  
  197.    move.l   a5,d0
  198.    move.l   (sp)+,a5
  199.    rts
  200.  
  201. ;----------------------------------------------------------------------
  202. ;
  203. ; here begins the system interface commands.  When the user calls
  204. ; OpenLibrary/CloseLibrary/RemoveLibrary, this eventually gets translated
  205. ; into a call to the following routines (Open/Close/Expunge).  Exec
  206. ; has already put our library pointer in A6 for us.  Exec has turned
  207. ; off task switching while in these routines (via Forbid/Permit), so
  208. ; we should not take too long in them.
  209. ;
  210. ;----------------------------------------------------------------------
  211.  
  212.    ; Open returns the library pointer in d0 if the open
  213.    ; was successful.  If the open failed then null is returned.
  214.    ; It might fail if we allocated memory on each open, or
  215.    ; if only open application could have the library open
  216.    ; at a time...
  217.  
  218. Open:      ; ( libptr:a6, version:d0 )
  219.  
  220.    ;------ mark us as having another opener
  221.    addq.w   #1,LIB_OPENCNT(a6)
  222.  
  223.    ;------ prevent delayed expunges
  224.    bclr   #LIBB_DELEXP,sb_Flags(a6)
  225.  
  226.    move.l   a6,d0
  227.    rts
  228.  
  229.    ; There are two different things that might be returned from
  230.    ; the Close routine.  If the library is no longer open and
  231.    ; there is a delayed expunge then Close should return the
  232.    ; segment list (as given to Init).  Otherwise close should
  233.    ; return NULL.
  234.  
  235. Close:      ; ( libptr:a6 )
  236.     
  237.    ;------ set the return value
  238.    CLEAR   d0
  239.  
  240.    ;------ mark us as having one fewer openers
  241.    subq.w   #1,LIB_OPENCNT(a6)
  242.  
  243.    ;------ see if there is anyone left with us open
  244.    bne.s   1$
  245.  
  246.    ;------ see if we have a delayed expunge pending
  247.    btst   #LIBB_DELEXP,sb_Flags(a6)
  248.    beq.s   1$
  249.  
  250.    ;------ do the expunge
  251.    bsr   Expunge
  252. 1$:
  253.    rts
  254.  
  255.  
  256.    ; There are two different things that might be returned from
  257.    ; the Expunge routine.  If the library is no longer open
  258.    ; then Expunge should return the segment list (as given to
  259.    ; Init).  Otherwise Expunge should set the delayed expunge
  260.    ; flag and return NULL.
  261.    ;
  262.    ; One other important note: because Expunge is called from
  263.    ; the memory allocator, it may NEVER Wait() or otherwise
  264.    ; take long time to complete.
  265.  
  266. Expunge:   ; ( libptr: a6 )
  267.  
  268.    movem.l   d2/a5/a6,-(sp)
  269.    move.l   a6,a5
  270.    move.l   sb_SysLib(a5),a6
  271.    
  272.    ;------ see if anyone has us open
  273.    tst.w   LIB_OPENCNT(a5)
  274.    beq   1$
  275.  
  276.    ;------ it is still open.  set the delayed expunge flag
  277.    bset   #LIBB_DELEXP,sb_Flags(a5)
  278.    CLEAR   d0
  279.    bra.s   Expunge_End
  280.  
  281. 1$:
  282.    ;------ go ahead and get rid of us.  Store our seglist in d2
  283.    move.l   sb_SegList(a5),d2
  284.  
  285.    ;------ unlink from library list
  286.    move.l   a5,a1
  287.    CALLSYS   Remove
  288.    
  289.    ;
  290.    ; device specific closings here...
  291.    ;
  292.  
  293.    ;------ close the dos library
  294.    move.l   sb_DosLib(a5),a1
  295.    CALLSYS   CloseLibrary
  296.  
  297.    ;------ free our memory
  298.    CLEAR   d0
  299.    move.l   a5,a1
  300.    move.w   LIB_NEGSIZE(a5),d0
  301.  
  302.    sub.l   d0,a1
  303.    add.w   LIB_POSSIZE(a5),d0
  304.  
  305.    CALLSYS   FreeMem
  306.  
  307.    ;------ set up our return value
  308.    move.l   d2,d0
  309.  
  310. Expunge_End:
  311.    movem.l   (sp)+,d2/a5/a6
  312.    rts
  313.  
  314.  
  315. Null:
  316.    CLEAR   d0
  317.    rts
  318.  
  319. ;----------------------------------------------------------------------
  320. ; Here begins the library functions.
  321. ;
  322. ; These simple assembler functions are only entries to actual functions
  323. ; written in C and contained in the C module hrcode.c. The purpose of these
  324. ; entry functions is to push the arguments into stack and then call C code.
  325. ;
  326. ;----------------------------------------------------------------------
  327.  
  328.  
  329. *----- R3DInitDspDrv( )
  330. R3DInitDspDrv:
  331.     jsr    _R3DInitDspDrv
  332.     rts
  333.  
  334. *----- R3DFreeDspDrv(a0)
  335. R3DFreeDspDrv:
  336.     move.l a0,-(sp)
  337.     jsr    _R3DFreeDspDrv
  338.     addq   #4,sp
  339.     rts
  340.  
  341. *----- R3DSetMode(a0)
  342. R3DSetMode:
  343.     move.l a0,-(sp)
  344.     jsr    _R3DSetMode
  345.     addq   #4,sp
  346.     rts
  347.  
  348. *----- R3DGetSize(a0,a1,d0)
  349. R3DGetSize:
  350.     move.l d0,-(sp)
  351.     move.l a1,-(sp)
  352.     move.l a0,-(sp)
  353.     jsr    _R3DGetSize
  354.     addq   #8,sp
  355.     addq   #4,sp
  356.     rts
  357.  
  358. *----- R3DWriteLine(a0,a1,a2,d0,d1)
  359. R3DWriteLine:
  360.     move.l d1,-(sp)
  361.     move.l d0,-(sp)
  362.     move.l a2,-(sp)
  363.     move.l a1,-(sp)
  364.     move.l a0,-(sp)
  365.     jsr    _R3DWriteLine
  366.     addq   #8,sp
  367.     addq   #8,sp
  368.     addq   #4,sp
  369.     rts
  370.  
  371. *----- R3DReadLine(a0,a1,a2,d0,d1)
  372. R3DReadLine:
  373.     move.l d1,-(sp)
  374.     move.l d0,-(sp)
  375.     move.l a2,-(sp)
  376.     move.l a1,-(sp)
  377.     move.l a0,-(sp)
  378.     jsr    _R3DReadLine
  379.     addq   #8,sp
  380.     addq   #8,sp
  381.     addq   #4,sp
  382.     rts
  383.  
  384. *----- R3DClsScr(a0,a1)
  385. R3DClsScr:
  386.     move.l a1,-(sp)
  387.     move.l a0,-(sp)
  388.     jsr    _R3DClsScr
  389.     addq   #8,sp
  390.     rts
  391.  
  392. *----- R3DCustomSave(a0,a1,a2,d0,d1,d2)
  393. R3DCustomSave:
  394.     move.l d2,-(sp)
  395.     move.l d1,-(sp)
  396.     move.l d0,-(sp)
  397.     move.l a2,-(sp)
  398.     move.l a1,-(sp)
  399.     move.l a0,-(sp)
  400.     jsr    _R3DCustomSave
  401.     addq   #8,sp
  402.     addq   #8,sp
  403.     addq   #8,sp
  404.     rts
  405.  
  406.  
  407. EndCode:
  408.  
  409.    END
  410.